package cn.anc.aonicardv.util;


import java.io.IOException;
import java.util.Calendar;

import cn.anc.httpcontrolutil.cache.CacheManager;

/**
 * function : 日志输出.
 * <p/>
 */
@SuppressWarnings("unused")
public final class LogUtil {
    public static boolean DEBUG = true;

    public static void w(String tag, String content) {
        if (DEBUG) {
            android.util.Log.w(tag, content);
        }
    }

    public static void w(final String tag, Object... objs) {
        if (DEBUG) {
            android.util.Log.w(tag, getInfo(objs));
        }
    }

    public static void i(String tag, String content) {
        if (DEBUG) {
            android.util.Log.i(tag, content);
        }
    }

    public static void i(final String tag, Object... objs) {
        if (DEBUG) {
            android.util.Log.i(tag, getInfo(objs));
        }
    }

    public static void d(String tag, String content) {
        if (DEBUG) {
            android.util.Log.d(tag, content);
        }
    }

    public static void d(final String tag, Object... objs) {
        if (DEBUG) {
            android.util.Log.d(tag, getInfo(objs));
        }
    }

    public static void e(String tag, String content) {
        if (DEBUG) {
            android.util.Log.e(tag, content);
        }
    }

    public static void e(String tag, String content, Throwable e) {
        if (DEBUG) {
            android.util.Log.e(tag, content, e);
        }
    }
    public static void writeFile(String tag, String content) {
        //路测速度打印
        String saveStr = DateUtils.getCurrentDateTime() + "||" + content;
        try {
            boolean b = FileUtils.writeFile(CacheManager.CACHE_ROOT_DIR + "/" + "videoInfo" + ".txt", saveStr + "\n", true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    public static void e(final String tag, Object... objs) {
        if (DEBUG) {
            android.util.Log.e(tag, getInfo(objs));
        }
    }

    private static String getInfo(Object... objs) {
        StringBuilder sb = new StringBuilder();
        if (null == objs) {
            sb.append("no mesage.");
        } else {
            for (Object object : objs) {
                sb.append(object);
            }
            sb.append("-");
        }
        return sb.toString();
    }

    public static void sysOut(Object msg) {
        if (DEBUG) {
            System.out.println(msg);
        }
    }

    public static void sysErr(Object msg) {
        if (DEBUG) {
            System.err.println(msg);
        }
    }
    private static Calendar mCalendar;
    public static void writeFileOfLog(String msg) {
        mCalendar = Calendar.getInstance();
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        String logString = String.format("[%1$02d:%2$02d:%3$02d:%4$02d] %5$s\n",
                mCalendar.get(Calendar.HOUR_OF_DAY),
                mCalendar.get(Calendar.MINUTE),
                mCalendar.get(Calendar.SECOND),
                mCalendar.get(Calendar.MILLISECOND),
                msg);
        try {
            boolean b = FileUtils.writeFile(CacheManager.CACHE_ROOT_DIR + "/" + "VideoLoadingLog" + ".txt", logString + "\n", true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
